//
//  ViewController.m
//  10-CustomTableViewCell
//
//  Created by Snow on 16/7/27.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ViewController.h"
#import "CustomTableViewCell.h"
#import "TestTableViewCell.h"
#import "NewsObject.h"
#define  kReuse @"reuse"
#define kCustom @"custom"
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableViewOfClass;
@property (nonatomic, strong) NSMutableArray *arrayOfClass;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //数据的传递 依赖modal 传对象 存对象 取对象
    NewsObject *object = [[NewsObject alloc] initWithNewsImage:@"1" newsTitle:@"刘在石" newsDescription:@"刘在石与GirlsDay成员跳舞 不忍直视 自称[刘赫]" newsNumberCount:@"3万人跟帖"];
    
    self.arrayOfClass = [NSMutableArray arrayWithObjects:object, object, object, object, object, nil];
//    NSString *path = [[NSBundle mainBundle] pathForResource:@"DLS160710" ofType:@"plist"];
//    NSArray *array = [NSArray arrayWithContentsOfFile:path];
//    self.arrayOfClass = [NSMutableArray arrayWithArray:array];
    self.tableViewOfClass = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableViewOfClass.delegate = self;
    self.tableViewOfClass.dataSource = self;
    [self.tableViewOfClass registerClass:[TestTableViewCell class] forCellReuseIdentifier:kReuse];
    [self.view addSubview:self.tableViewOfClass];
    //使用自定义cell 需要修改
    //1.注册对应cell类型
    //2.重用池取出cell的类型
    //3.自定义cell继承于UITableViewcell
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
    //多种cell混合使用
    //注册cell 重用标识不要相同
    [_tableViewOfClass registerClass:[CustomTableViewCell class] forCellReuseIdentifier:kCustom];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    [self.tableViewOfClass setEditing:editing animated:animated];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrayOfClass.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //多种cell同时使用时 可以根据下标进行区分
    //注意:判断情况一定要判断完整
    if (indexPath.row == 1) {
        CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustom];
        return cell;
    } else {
    TestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kReuse];
    cell.newsObject = _arrayOfClass[indexPath.row];
//    NSDictionary *dic = [self.arrayOfClass objectAtIndex:indexPath.row];
//    cell.textLabel.text = [dic objectForKey:@"name"];
//    cell.imageviewOfPic.image = [UIImage imageNamed:@"1"];
//    cell.labelOfTitle.text = @"刘在石";
//    cell.labelOfContent.text = @"刘在石与GirlsDay成员跳舞 不忍直视 自称[刘赫]";
//    cell.labelOfContent.numberOfLines = 0;
//    cell.labelOfContent.font = [UIFont systemFontOfSize:15];
//    cell.labelOfNumber.text = @"3万人跟帖";
    return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 110;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
